import typing
import dataclasses
import ipywidgets as widgets
from src.utils.params import Params
from src.utils.config import Config
from IPython.display import display, update_display


@dataclasses.dataclass
class Interface:
    config: Config
    params: Params
    display_id: int = 1488

    def __post__init__(self):
        self._output = widgets.Output(layout={'border': '1px solid black'})

    @classmethod
    def from_interface(cls, interface: 'Interface'):
        return cls(
            config=interface.config,
            params=interface.params
        )

    def to_interface(self, interface: 'Interface'):
        return interface(self.config, self.params)

    def display(self, *widgets, **kwargs):
        return display(*widgets, self.display_id, **kwargs)

    def update_display(self, obj: widgets.Widget):
        return update_display(obj=obj, display_id=self.display_id)

    @property
    def output(self):
        with self._output:
            for i in range(10):
                print(i, 'Hello world!')

    @staticmethod
    def change_children(main_widget: widgets.Widget, value: widgets.Widget | typing.Any, method=list.append):
        children = list(main_widget.children)
        method(children, value)
        main_widget.children = children
        return main_widget

    def tabs(self, *interfaces: 'Interface'):
        self.tab = widgets.Tab().add_class('main_tab')
        self.tab.children = [interface.box for interface in interfaces]
        for index, interface in enumerate(interfaces, start=0):
            self.tab.set_title(index, interface.name)
        self.display(self.tab)

    def style(self):
        ...

    def __call__(self, *args: typing.Any, **kwds: typing.Any) -> typing.Any:
        ...
